<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class Model_Nilai_Siswa_Detail extends MY_Model {
	
	public function __construct() {

		parent::__construct();

		$this->table_name = 'aka_nilai_detail2';

		$this->primary_key = 'aka_nilai_detail2.nilai_detail2_id';

	}
	function get_nilai_siswa_detail($nilai_semester_id){
	
		$this->load->database();
		
			$sql = "select aka_nilai_detail2.*,aka_nilai_semester.nama from aka_nilai_detail2 join aka_nilai_semester on aka_nilai_detail2.nilai_semester_id=aka_nilai_semester.nilai_semester_id WHERE aka_nilai_detail2.nilai_semester_id='$nilai_semester_id'  order by aka_nilai_detail2.nilai_detail2_id";
				
		$query = $this->db->query($sql);
		$this->db->close();
		return $query;
	}
	
	function get_by($id){
		$this->load->database();		
		$sql = "SELECT * FROM {$this->table_name} WHERE {$this->primary_key}='$id';";
		$query = $this->db->query($sql);
		$this->db->close();
		return $query;
	}
	
	function add($data){
		$this->load->database();
			$this->db->trans_start();
				$this->db->insert($this->table_name,$data);
			$this->db->trans_complete();
			
			if ($this->db->trans_status() === FALSE)
			{
				$this->session->set_flashdata('error','Data gagal disimpan.');
			}else{
				$this->session->set_flashdata('success','Data berhasil disimpan.');
			}
		$this->db->close();
	}
	
	function edit($id,$data){
		$this->load->database();
			$this->db->trans_start();
				$this->db->where($this->primary_key,$id);
				$this->db->update($this->table_name,$data);
			$this->db->trans_complete();
			
			if ($this->db->trans_status() === FALSE)
			{
				$this->session->set_flashdata('error','Data gagal disimpan.');
			}else{
				$this->session->set_flashdata('success','Data berhasil disimpan.');
			}
		$this->db->close();
	}
	
	function delete($id){
		$this->load->database();
			$this->db->trans_start();
				$sql = "DELETE FROM {$this->table_name} WHERE {$this->primary_key}='$id'";
				$this->db->query($sql);
			$this->db->trans_complete();
			
			if ($this->db->trans_status() === FALSE)
			{
				$this->session->set_flashdata('error','Data gagal dihapus.');
			}else{
				$this->session->set_flashdata('success','Data berhasil dihapus.');
			}
		$this->db->close();
	}
	
}

?>